

function [f,gr] = mr_no_randomC2(b)

global dat
global dat2
global g
global D
global k

yy=0;
gra=zeros(1,2*k+0+1);

for i = 1:g
    yt = dat(i).yt;
    wt = dat(i).wt;
    xt = dat(i).xt;
  
    
    [mr junk] = size(xt);   
     
 
    
    indp_b1=zeros(mr,1);
    indp_b2=zeros(mr,1);
    gra_g=zeros(mr,2*k+0+1);  
     
    
        bb=xt*b(1:k+0)+wt*xt(:,1:k)*b(k+0+1:2*k+0)+b(2*k+0+1)*ones(mr,1); 
          
                       
        indp_b1=indp_b1+ 1./(1+exp(-2*bb));
        indp_b2=indp_b2+ 1./(1+exp(2*bb));
   
     
     yy=yy+ ((ones(mr,1)+yt)'/2*log(indp_b1)+(ones(mr,1)-yt)'/2*log(indp_b2));
    
   
        temp4=[xt wt*xt(:,1:k) ones(mr,1)]; 
            
        gra_g=gra_g+temp4;
        
  
    gra1=2*((ones(mr,1)+yt)/2-indp_b1)'*gra_g;


    
    gra=gra+gra1;
end

    f=-yy;
    
    
    gr = -gra';
    